package com.xuetang9.t9.hotel.services.impl;

import com.xuetang9.t9.hotel.beans.BillDetail;
import com.xuetang9.t9.hotel.mapper.IBillDetailMapper;
import com.xuetang9.t9.hotel.mapper.condition.impl.BillDetailCondition;
import com.xuetang9.t9.hotel.services.IBillDetailService;
import com.xuetang9.t9.hotel.services.ICommodityExpenseService;
import com.xuetang9.t9.hotel.utils.ResponseResult;
import com.xuetang9.t9.hotel.utils.SnowFlake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BillDetailServiceImpl implements IBillDetailService {

    @Autowired
    private IBillDetailMapper billDetailMapper;

    @Autowired
    private SnowFlake snowFlake;

    @Autowired
    private ICommodityExpenseService commodityExpenseService;


    @Override
    public boolean save(BillDetail billDetail) {
        if(null == billDetail){
            return false;
        }
        if(billDetail.getArriveId() == null){
            return false;
        }
        billDetail.setBillId(snowFlake.nextId());
        return billDetailMapper.insert(billDetail) > 0;
    }

    @Override
    public boolean alter(BillDetail billDetail) {
        if(null == billDetail){
            return false;
        }
        return billDetailMapper.update(billDetail) > 0;
    }

    @Override
    public boolean remove(Long id) {
        if(id == null) {
            return false;
        }
        commodityExpenseService.removeByBillId(id);
        return billDetailMapper.deleteById(id) > 0;
    }

    @Override
    public boolean removeByArriveId(Long id) {
        if(id == null){
            return false;
        }
        commodityExpenseService.removeByBillId(id);
        return billDetailMapper.deleteByArriveId(id) > 0;
    }

    @Override
    public ResponseResult findByAll(BillDetailCondition billDetailCondition) {
        return null;
    }

    @Override
    public ResponseResult findByCount(BillDetailCondition billDetailCondition) {
        return null;
    }
}
